#!/bin/bash

# for (( 初始化变量; 条件; 自增/自减 ))
# do
#     代码块
# done
#自增
# for (( a=1; a<=3; a++))
# do
#     echo  ${a}
# don

# for (( a=1; a<=3; ++a))
# do
#     echo  ${a}  
# done

#自减
# for (( a=3; a>0 ;a-- ))
# do
#     echo  ${a}
# done


# 优化用户登陆的代码
username="root"
password="abc123"
for (( a=2; a >= 0; --a ))
do
    read  -p "输入用户名:" user
    read  -t 30 -s -p "输入密码:" pass
    if  [ $username  == $user  -a $password  == $pass ];then
        echo " "
        echo -e "\n登录系统成功"
    else
        echo " "
        echo "登录失败，请检查用户名或者密码是否输入错误"
    fi
    # a=`echo "3-$i"| bc`
    # # a=`echo "3-$i"| expr`
    echo  "剩余${a}次"
done






#用户登陆
name="root"
password="abc123"
for (( i=2; i>=0;i-- ))
do
    read -p "请输入用户名：" name_enter
    if [  $name_enter  ==  $name ];then
        read -p "请输入密码：" pass
        if [ $password  ==  $pass ];then
            echo  "登录成功！！！"
            break  #在循环体中遇到break语句会终止循环
        else
            echo  "密码错误；请重新输入密码"
            echo "您还可以尝试 $i 次机会"
        fi

    else
        echo "用户名错误；请重新输入用户名"
        echo "您还可以尝试 $i 次机会"
    fi
done